package sample.hystrix.provider.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.web.bind.annotation.*;
import sample.hystrix.provider.utils.ApplicationContextUtil;

@RestController
@RequestMapping("provider")
public class HystrixController {

    @GetMapping(path="/test")
    public String test(@RequestParam("str")String str){
//        try {
//            Thread.sleep(10000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        StringBuilder builder = new StringBuilder();
        String port=ApplicationContextUtil.applicationContext.getEnvironment().getProperty("server.port");
        builder.append("Hello,I'm Provider-").append(port).append(".Your message is:").append(str);
        return builder.toString();
    }

    public String testFail(String str){
        return "超时！";
    }
}
